class Solution {
public:
    int kthToLast(ListNode* head, int k) {
        //快慢指针
        ListNode* slow=head;
        ListNode* fast=head;
        //先让快指针走k步
        while(k--)
        {
            fast=fast->next;
        }
        //同时走
        while(fast)
        {
            fast=fast->next;
            slow=slow->next;
        }
        //慢指针就是倒数第k个节点
        return slow->val;
    }
};